home *** CD-ROM | disk | FTP | other *** search
- /* StatusWindow.c */
-
- /* StatusWindow XCMD for HyperCard
- with LightSpeedC v. 3.01 - 11/20/88
- Copyright 1988 by
- Puts up a modeless dialog that displays Sam Thornton
- Mac Model/CPU/FPU, number of KB free in PO Box 123
- the application heap, name, size, and free Fairfield NE 68938
- bytes of current stack, and the time. Some portions Copyright
- Buttons for basic HyperCard navigation, by Symantec and Apple.
- stack/heap compaction, date, and transfer
- to other stacks/applications are provided. Compuserve: 71750,667
- See StatusWindow.docs for user interface GEnie: S.THORNTON5
-
- NOTE: All 'StringPtr' types in May be copied and
- HyperXCmd.h should distributed for personal
- be dereferenced to type 'Ptr' use without charge only,
- for this to compile properly. except for nominal
- distribution fees. For
- commercial use or
- distribution, contact
- author, above. */
- #include "HyperXCmd.h"
- #include "SetUpA4.h"
- #include "MemoryMgr.h"
- #include "WindowMgr.h"
- #include "DialogMgr.h"
- #include "EventMgr.h"
- #include "MacTypes.h"
- #include "QuickDraw.h"
- #include "unix.h"
- #include "FileMgr.h"
- #include "DeviceMgr.h"
- #include "OSUtil.h"
- #include "strings.h"
- #include "FileMgr.h"
- #include "ResourceMgr.h"
-
- pascal void SendCardMsg(Ptr msg); /* OUR INTERNAL VERSIONS */
- pascal Handle EvalCmd(Ptr expr); /* OF HC CALLBACKS */
-
- /* ===================================================================== */
- /* SOME CONSTANTS... */
- /* ===================================================================== */
- #define MAIN_DIALOG 297 /* RESOURCE ID FOR OUR DIALOG */
- #define _OPEN 10 /* OPEN button */
- #define _RECENT 9 /* RECENT button */
- #define _DATE_TIME 8 /* TIME button */
- #define _COMPACT 7 /* COMPACT button */
- #define _NEXT 6 /* NEXT button (uses HyperCard ICON) */
- #define _HOME 5 /* HOME button (uses HyperCard ICON) */
- #define _PREV 4 /* PREV button (uses HyperCard ICON) */
- #define _MACHINE 3 /* ITEM ID FOR HARDWARE/MEM DISPLAY */
- #define _TIME 2 /* ITEM ID FOR DATE/TIME DISPLAY */
- #define _CURR_STACK 1 /* ITEM ID FOR CURRENT STACK INFO DISPLAY */
- #define NULL 0L
- #define _QUIT 99 /* ARBITRARY VALUE FOR QUIT FLAG */
- /* ===================================================================== */
-
- typedef struct trade_mark {
- char mk[90];
- } trade_mark;
-
- trade_mark mrk = {" StatusWindow XCMD Copyright 1988 by Sam Thornton * PO Box 123 * Fairfield NE 68938 "};
-
- /* ===================================================================== */
- /* SET ASIDE SOME GLOBALS FOR LAZIER PARAMETER MANAGEMENT */
- /* ===================================================================== */
- static char machine[31]; /* short machine name */
- static DialogPtr master_ptr; /* Our dialog pointer */
- static WindowPtr old_window; /* HyperCard's Window */
- static long cur_mem; /* CHECK MEM FOR REDISPLAY */
- static int dt_mode; /* FLAG: DISPLAY DATE OR TIME */
- static long the_ticks; /* OUR GLOBAL COUNTDOWN TIMER */
- static Rect myGlobalRect; /* H/C SCREEN DISPLAY AREA */
- static XCmdBlockPtr myParamPtr; /* COPY OF HYPERCARD CALLBACK */
- /* ===================================================================== */
- /* ENTRY POINT */
- /* ===================================================================== */
-
- pascal void main (paramPtr)
- XCmdBlockPtr paramPtr;
- {
- int itemHit, mem_size;
- char my_machine[31];
- pascal Boolean MyFilter();
- GrafPtr current_port;
- SysEnvRec environment;
-
- RememberA0();
- SetUpA4();
-
- /* DO SOME CLEANUPS */
- myParamPtr = paramPtr;
- SendCardMsg("\phide msg"); /* Fixes la Bomba on selection of Msg Box */
- SendCardMsg("\pset cursor to 4");
- old_window = FrontWindow(); /* so we can kill HC window on XFERs */
-
- /* DESCRIBE THE AREA IN WHICH OUR DIALOG CAN BE MOVED */
- /* NOTE: can't seem to use 'screenBits.bounds' from HyperCard, so... */
- GetPort(¤t_port);
- myGlobalRect = current_port->portRect;
- myGlobalRect.top += 20;
- InsetRect (&myGlobalRect, 4, 4);
-
- SetDAFont(geneva);
- master_ptr = GetNewDialog(MAIN_DIALOG, 0, -1L);
-
- /* CHECK TO MAKE SURE THERE WAS ENOUGH MEMORY */
- if (master_ptr == NULL) { /* oops! -- we're gone */
- SysBeep(1);
- goto PANIC;
- }
-
- /* GET THE MACHINE/CPU/FPU TYPE */
-
- SysEnvirons(99,&environment); /* NOTE: USE A HIGH VERS.NUMBER */
-
- switch(environment.machineType) {
- case envMachUnknown:
- strcpy(my_machine,"NewMac");
- break;
- case env512KE:
- strcpy(my_machine,"Mac512KE");
- break;
- case envMacPlus:
- strcpy(my_machine,"MacPlus");
- break;
- case envSE:
- strcpy(my_machine,"MacSE");
- break;
- case envMacII:
- strcpy(my_machine,"MacII");
- break;
- case envMac:
- strcpy(my_machine,"Mac64K");
- break;
- case envXL:
- strcpy(my_machine,"MacXL");
- break;
- default:
- strcpy(my_machine,"???Mac");
- break;
- }
- strcpy(machine,my_machine);
- strcat(machine,": ");
- switch(environment.processor) {
- case envCPUUnknown:
- strcat(my_machine,"*NEW CPU");
- break;
- case env68000:
- strcat(my_machine,"*68000");
- break;
- case env68010:
- strcat(my_machine,"*68010");
- break;
- case env68020:
- strcat(my_machine,"*68020");
- break;
- default:
- strcat(my_machine,"*CPU???");
- break;
- }
- if (environment.hasFPU)
- strcat(my_machine,"(68881)");
- CtoPstr(my_machine);
- SetWTitle(master_ptr, &my_machine);
-
- /* SET DATE/TIME FLAG FOR DISPLAY OF CURRENT TIME: 0=time, 1=date */
- dt_mode = 0;
- show_mem();
- Get_Stack_Name();
- ShowWindow(master_ptr);
- InitCursor ();
-
- /* LOOP THRU MODALDIALOG UNTIL CLOSEBOX IS CLICKED */
- do {
-
- ModalDialog(MyFilter, &itemHit);
-
- } while (itemHit != _QUIT);
-
- /* BYE....*/
- DisposDialog(master_ptr);
- PANIC:
- SetDAFont(systemFont);
- compact_it();
- RestoreA4();
- return;
- }
-
- /* ===================================================================== */
- /* MODALDIALOG FILTERPROC HANDLES OUR MEAGER REQUIREMENTS */
- /* ===================================================================== */
-
- pascal static Boolean MyFilter(dptr, theEvent, itemHit)
- DialogPtr dptr; EventRecord *theEvent; int *itemHit;
- {
- int theHit; /* LOCAL SPARE */
- Handle item_handle;
- int item_type;
- Rect item_rect;
- Handle answer;
-
- if (Ticks >= the_ticks) show_mem(); /* IF TIMER ELAPSED, UPDATE */
-
- if (dptr != master_ptr) return (false);
-
- /* IF NO MOUSEHIT, LET MODALDIALOG HANDLE THIS CYCLE */
- if (theEvent->what != mouseDown) return (false);
-
- /* FIND OUT WHERE THE MOUSE WAS CLICKED AND HANDLE IT */
- /* NOTE: Since this is strictly a ModalDialog subroutine, we don't
- have to worry about hits in other parts of the screen */
-
- switch(FindWindow(theEvent->where, &dptr)) {
-
- case inDrag: /* DRAG DIALOG AROUND - NOTE: callback routine
- modified in XCMD.c to dereference msg param */
-
- DragWindow(dptr, theEvent->where, &myGlobalRect);
- show_mem();
- /* lazy update of HC screen */
- SendCardMsg("\pgo this card");
-
- return(true);
-
- case inGoAway: /* SET ITEMHIT TO OUR QUIT FLAG, IF APPROPRIATE */
- if (TrackGoAway(dptr, theEvent->where)) *itemHit = _QUIT;
- return(true);
-
- case inContent: /* RESPOND TO HITS IN OUR DIALOG CONTENT REGION */
- if (DialogSelect(theEvent, &dptr, &theHit)) {
-
- switch(theHit) {
-
- case _COMPACT:
-
- if (theEvent->modifiers & optionKey) {
- compact_it();
- SendCardMsg("\pset lockMessages to true");
- SendCardMsg("\pdoMenu \"Compact Stack\"");
- SendCardMsg("\pset cursor to 4");
- SendCardMsg("\pset lockMessages to false");
- comp_Mem();
- Get_Stack_Name();
- InitCursor();
- }
- else comp_Mem();
- return(true);
-
- case _DATE_TIME:
- dt_mode = 1;
- show_mem();
- return(true);
-
- case _OPEN:
- DoMyOpen();
- return(true);
-
- case _RECENT:
- set_card();
-
- if (theEvent->modifiers & optionKey) {
- SendCardMsg("\ppush card");
- SendCardMsg("\pdoMenu recent");
- }
- else {
- SendCardMsg("\pset cursor to 4");
- SendCardMsg("\ppop card");
- }
- SendCardMsg("\pset lockmessages to false");
- Get_Stack_Name();
- show_mem();
- InitCursor();
- return(true);
-
- case _PREV:
- case _NEXT:
- case _HOME:
- SetPort(master_ptr);
- GetDItem(master_ptr,theHit,&item_type,&item_handle,&item_rect);
- if (theHit == _HOME)
- InsetRect(&item_rect,1,5);
- else InsetRect(&item_rect,3,4);
- InvertRect(&item_rect);
- SendCardMsg("\pset lockmessages to true");
-
- if (theHit == _PREV) {
- SendCardMsg("\pvisual scroll right to gray");
- SendCardMsg("\pvisual scroll right");
- SendCardMsg("\pgo prev card");
- }
- else if (theHit == _NEXT) {
- SendCardMsg("\pvisual scroll left to gray");
- SendCardMsg("\pvisual scroll left");
- SendCardMsg("\pgo next card");
- }
- else if (theHit == _HOME) {
- SendCardMsg("\pset cursor to 4");
- push_card();
- SendCardMsg("\pgo home");
- Get_Stack_Name();
- InitCursor();
- }
- SetPort(dptr);
- InvertRect(&item_rect);
- SendCardMsg("\pset lockmessages to false");
- return(true);
-
- } /* END OF 'IN CONTENT' SWITCH */
-
- } /* END OF 'IF DIALOGSELECT' */
-
- } /* END OF FINDWINDOW SWITCH */
-
- return(false); /* nothing interesting happened--let's bore ModalDialog */
-
- } /* END OF FUNCTION */
-
- /* ===================================================================== */
- /* COMPACT THE APPLICATION HEAP AND JSR TO DISPLAY ROUTINE */
- /* ===================================================================== */
-
- comp_Mem()
- {
- compact_it();
- show_mem();
- return;
- }
-
- /* ===================================================================== */
- /* COMPACT THE APPLICATION HEAP */
- /* ===================================================================== */
-
- compact_it()
- {
- Size grow;
-
- MaxMem(&grow);
- MaxApplZone();
- return;
- }
-
- /* ===================================================================== */
- /* FUNCTION TO DISPLAY CURRENT MEMSIZE & TIME (OR DATE) IN OUR DIALOG */
- /* ===================================================================== */
-
- show_mem()
- {
- char time_string[11];
- char mem_string[11];
- Handle item_handle;
- int item_type;
- Rect item_rect;
- char temp_string[256];
- GrafPtr old_port;
-
- GetPort(&old_port);
- SetPort(master_ptr);
- PenNormal();
- TextSize(9); /* 9-POINT */
-
- /* GET AVAILABLE MEMORY */
- if (TheZone->zcbFree != cur_mem) {
- cur_mem = TheZone->zcbFree;
- strcpy(temp_string, machine);
- stci_d(mem_string, (int)(cur_mem/1024), 9);
- strcat(temp_string, mem_string);
- strcat(temp_string,"K free\0");
- CtoPstr(temp_string);
- GetDItem(master_ptr,_MACHINE,&item_type,&item_handle,&item_rect);
- SetIText(item_handle, temp_string);
- }
-
- /* WE EITHER WANT THE CURRENT TIME...*/
- if (dt_mode == 0) {
- /* '1' = HH:MM:SS format */
- IUTimeString(Time, 1, &time_string);
- strcpy(temp_string,"Time: \0");
- }
- /* ...OR WE WANT THE CURRENT DATE */
- else if (dt_mode == 1) {
- /* '0' = MM/DD/YY format */
- IUDateString(Time, 0, &time_string);
- strcpy(temp_string,"Date: \0");
- dt_mode = 0;
- }
- PtoCstr(time_string);
- strcat(temp_string,time_string);
- CtoPstr(temp_string);
- GetDItem(master_ptr,_TIME,&item_type,&item_handle,&item_rect);
- SetIText(item_handle, temp_string);
- the_ticks = Ticks + 55; /* RESET OUR TIMER */
- SetPort(old_port);
- return;
- }
-
- /* ===================================================================== */
- /* GET THE NAME OF THE CURRENT STACK */
- /* ===================================================================== */
-
- Get_Stack_Name()
- {
- Handle answer;
- char temp_string[128];
- Handle item_handle;
- int item_type;
- Rect item_rect;
-
- answer = EvalCmd( "\pthe short name of this stack");
- strcpy(temp_string, "\"");
- strcat(temp_string, *answer);
- strcat(temp_string, "\" : \0");
- DisposHandle(answer);
-
- answer = EvalCmd( "\pround(the size of this stack/1024)");
- strcat(temp_string, *answer);
- strcat(temp_string, "K : \0");
- DisposHandle(answer);
-
- answer = EvalCmd( "\pround(the freesize of this stack/1024)");
- strcat(temp_string, *answer);
- strcat(temp_string, "K free");
- DisposHandle(answer);
-
- CtoPstr(temp_string);
- GetDItem(master_ptr,_CURR_STACK,&item_type,&item_handle,&item_rect);
- SetIText(item_handle, temp_string);
- return;
- }
-
- /* ===================================================================== */
- /* OPEN ANOTHER APPLICATION OR STACK */
- /* ===================================================================== */
-
- DoMyOpen()
- {
-
- SFTypeList myTypes;
- Point SFGwhere;
- SFReply reply;
- char fn[64];
- char msg[256];
-
- myTypes[0] = 'APPL';
- myTypes[1] = 'STAK';
- SFGwhere.v = 90; /* NOTE: this is set for standard Mac/Mac+/SE size */
- SFGwhere.h = 82;
-
- SetDAFont(systemFont);
- SFGetFile( SFGwhere, "\p", 0L, 2, &myTypes, 0L, &reply );
- SendCardMsg("\pgo this card");
-
- if (reply.good) {
- SendCardMsg("\pset cursor to 4");
- pStrCopy( reply.fName, fn );
- PtoCstr(fn);
- if (reply.fType == 'STAK') {
- strcpy(msg, "go to stack \"");
- strcat(msg, fn);
- strcat(msg, "\"");
- CtoPstr(msg);
- push_card();
- SendCardMsg(msg);
- SendCardMsg("\pset lockmessages to false");
- Get_Stack_Name();
- }
- else {
- if (strcmp(fn, "HyperCard\0") != 0) {
-
- strcpy(msg, "open \"");
- strcat(msg, fn);
- strcat(msg, "\"");
- CtoPstr(msg);
- DisposDialog(master_ptr);
- HideWindow(old_window);
- SendCardMsg("\pgo this card");
- SendCardMsg(msg);
- return;
- }
- else {
- SysBeep(1); /* can't open HyperCard from HyperCard */
- SysBeep(1);
- }
- }
- }
- SetDAFont(geneva);
- InitCursor();
- return;
- }
-
- /* ===================================================================== */
- /* HYPERCARD CALLBACK SUB */
- /* ===================================================================== */
-
- push_card()
- {
- SendCardMsg("\ppush card");
- set_card();
- return;
- }
-
- /* ===================================================================== */
- /* HYPERCARD CALLBACK SUB */
- /* ===================================================================== */
-
- set_card()
- {
- SendCardMsg("\pset lockmessages to true");
- SendCardMsg("\pvisual dissolve to gray");
- SendCardMsg("\pvisual venetian blinds");
- return;
- }
-
- /* ===================================================================== */
- /* ROUTINE TO COPY A PASCAL STRING */
- /* ===================================================================== */
-
- pStrCopy( p1, p2 )
- register char *p1, *p2;
- /* copies a pascal string from p1 to p2 */
- {
- register int len;
-
- len = *p2++ = *p1++;
- while (--len>=0) *p2++=*p1++;
- }
-
- /* ===================================================================== */
- /* MOD. HYPERCARD CALLBACK SUBS */
- /* ===================================================================== */
-
- pascal void SendCardMsg(msg)
- Ptr msg;
- {
- myParamPtr->inArgs[0] = (long)msg;
- myParamPtr->request = xreqSendCardMessage;
- (*myParamPtr->entryPoint)();
- }
-
- pascal Handle EvalCmd(expr)
- Ptr expr;
- {
- myParamPtr->inArgs[0] = (long)expr;
- myParamPtr->request = xreqEvalExpr;
- (*myParamPtr->entryPoint)();
- return (Handle)myParamPtr->outArgs[0];
- }